home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / mcomm530.arc / ALLOCRB.C next >
C/C++ Source or Header  |  1990-09-08  |  2KB  |  43 lines

  1.  
  2. /*
  3.     ALLOCRB.C -- source file of code to allocate ring buffers and initialize
  4.      the required port structure members for MCOMM5 async routines.
  5.  
  6.     Mike Dumdei, 6 Holly Lane, Texarkana TX 75503  (c) 1989
  7. */
  8.  
  9. #if defined(__TURBOC__)
  10.     #include <alloc.h>
  11.     #define _fmalloc farmalloc
  12. #else
  13.     #include <malloc.h>
  14. #endif
  15. #include "comm.h"
  16.  
  17. int AllocRingBuffer(
  18.  ASYNC *port,                                 /* pointer to port structure */
  19.  int rxsize,                     /* number bytes to use for receive buffer */
  20.  int txsize,                    /* number bytes to use for transmit buffer */
  21.  int useFARmem)                   /* flag set if using FAR mem for buffers */
  22. {
  23.     unsigned long memptr;
  24.     int memsize;
  25.  
  26.     memsize = rxsize + txsize;
  27.  
  28.     if (useFARmem || sizeof(char *) == 4)              /* if FAR Ring bufs */
  29.         memptr = (unsigned long)_fmalloc(memsize);
  30.     else                                /* if Ring buffers use NEAR memory */
  31.         memptr = (unsigned long)(unsigned int)malloc(memsize);
  32.  
  33.      /* pre-initialize 4 required structure members */
  34.     port->RxSize = rxsize;                          /* receive buffer size */
  35.     port->TxSize = txsize;                         /* transmit buffer size */
  36.     port->RingSeg = (int)(memptr >> 16);                        /* SEG adr */
  37.     port->RingOfst = (int)memptr;                          /* OFST address */
  38.     if (memptr == 0L)
  39.         return 0;                       /* return 0 if no memory available */
  40.     return 1;                                 /* return 1, had some memory */
  41. }
  42.  
  43.